package com.nuc.iblog.service.imp;

import com.nuc.iblog.entity.Announcement;
import com.nuc.iblog.jpa.AnnouncementJpa;
import com.nuc.iblog.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MSAnnouncementService implements AnnouncementService {
    @Autowired
    AnnouncementJpa announcementJpa;
    @Override
    public int CreateAnnouncement(String content) {
        Announcement announcement=new Announcement();
        Date date=new Date();
        announcement.setAcontent(content);
        announcement.setAdate(date);
        announcementJpa.save(announcement);
        return 1;
    }

    @Override
    public Announcement getLatesetAnnouncement() {
        return announcementJpa.getLatestAnnouncement();
    }

    @Override
    public List<Announcement> getAllAnnouncements() {
        return announcementJpa.findAll();
    }
}
